using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using Campus.Entities;

namespace CampusSite.Models
{ 
    public class DiaDeLaSemanaRepository : IDiaDeLaSemanaRepository
    {
        CampusSiteContext context;        

        public DiaDeLaSemanaRepository()
        {
            context = new CampusSiteContext();
        }

        public DiaDeLaSemanaRepository(CampusSiteContext context)
        {
            this.context = context;
        }  

        public IQueryable<DiaDeLaSemana> All
        {
            get { return context.DiasDeLaSemana; }
        }

        public IQueryable<DiaDeLaSemana> AllIncluding(params Expression<Func<DiaDeLaSemana, object>>[] includeProperties)
        {
            IQueryable<DiaDeLaSemana> query = context.DiasDeLaSemana;
            foreach (var includeProperty in includeProperties) {
                query = query.Include(includeProperty);
            }
            return query;
        }

        public DiaDeLaSemana Find(int id)
        {
            return context.DiasDeLaSemana.Find(id);
        }

        public void InsertOrUpdate(DiaDeLaSemana diadelasemana)
        {
            if (diadelasemana.DiaDeLaSemanaId == default(int)) {
                // New entity
                context.DiasDeLaSemana.Add(diadelasemana);
            } else {
                // Existing entity
                context.Entry(diadelasemana).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var diadelasemana = context.DiasDeLaSemana.Find(id);
            context.DiasDeLaSemana.Remove(diadelasemana);
        }

        public void Save()
        {
            context.SaveChanges();
        }

        public void Dispose() 
        {
            context.Dispose();
        }
    }

    public interface IDiaDeLaSemanaRepository : IDisposable
    {
        IQueryable<DiaDeLaSemana> All { get; }
        IQueryable<DiaDeLaSemana> AllIncluding(params Expression<Func<DiaDeLaSemana, object>>[] includeProperties);
        DiaDeLaSemana Find(int id);
        void InsertOrUpdate(DiaDeLaSemana diadelasemana);
        void Delete(int id);
        void Save();
    }
}